package tool

import (
	"fmt"
	"sort"
)

// 将字符串切片转换为排序后的字符串，用于唯一标识一组元素
func KeyForGroup(group []string) string {
	sorted := make([]string, len(group))
	copy(sorted, group)
	sort.Strings(sorted)
	return fmt.Sprintf("%v", sorted)
}

// 判断两个 [][]string 是否内容相等（忽略子切片顺序）
func EqualIgnoreSubOrder(a, b [][]string) bool {
	counter := make(map[string]int)

	for _, slice := range a {
		key := KeyForGroup(slice)
		counter[key]++
	}

	for _, slice := range b {
		key := KeyForGroup(slice)
		counter[key]--
		if counter[key] == 0 {
			delete(counter, key)
		}
	}

	return len(counter) == 0
}
